<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>	
	<div class="myIframe_box">
		<div class="iframe_title">
			<div class="iframe_title_c">
				<div class="title_c_l">
					<span>菜单管理</span>
				</div>
			</div>
		</div>

		<div class="iframe_add"><a id="btnS" href="javascript:;">添加模块</a></div>

		<div class="middle_box">
			<table class="myTable" width="100%" cellspacing="0">
				<thead>
					<tr>
						<th>ID</th>
						<th>分类下拉</th>
						<th>排序号</th>
						<th>菜单名称</th>
						<th>链接</th>
						<th>状态</th>
					</tr>
				</thead>
				<tbody  id="myTbody" class="information">
					<?php
						if($articleList){

							foreach($articleList as $val){
							
								echo '<tr>
										<th class="arrI">'. $val['id'] .'</th>
										<th>
											<select class="classify">
												<option value="0">选择您的分类</option>';
								foreach($heat as $value){
									if($value['state'] === '0'){
										echo '<option value="'. $value['id'] .'">'. $value['username'] .'</option>';
									}
								}		
								echo '</select>
									</th>
									<th><input class="rank" type="text" name="rank" value="'. $val['rank'] .'"></th>
									<th><input class="menu" type="text" name="menu" value="'. $val['username'] .'"></th>
									<th><input class="link" type="text" name="link" value="'. $val['link'] .'"></th>
									<th><input class="state" type="checkbox" name="state" value="'. $val['state'] .'">禁用<i class="iconfont icon-shanchu2 del" onclick="return UI.hintCon({\'url\':\'./pose/menu_deleteAction.php?id='. $val['id'] .'\'})"></i></th>
								</tr>';
							}
						}
					?>
					
				</tbody>
			</table>
			<input id="btn" type="submit" value="保存">
		</div>
	</div>
</body>
</html>
<script type="text/javascript">
	// 添加列表模块
	var html = '<th class="arrI"></th>'+
				'<th><select class="classify">'+
					'<option value="0">选择您的分类</option><?php
						foreach($heat as $value){
									if($value['state'] === '0'){
										echo '<option value="'. $value['id'] .'">'. $value['username'] .'</option>';
									}
								}	
					?></select></th>'+
				'<th><input class="rank" type="text" name="rank"></th>'+
				'<th><input class="menu" type="text" name="menu"></th>'+
				'<th><input class="link" type="text" name="link"></th>'+
				'<th><input class="state" type="checkbox" name="state">禁用<i class="iconfont icon-shanchu2 del"></i></th>';

	document.getElementById('btnS').onclick = function(){

		UI.moduleList({'html':html});
	}

	// 显示与隐藏删除按钮
	showDel();

	// 状态码的选中状态
	var state = document.getElementsByClassName('state');

	for(var i = 0; i < state.length; i++){

		if(state[i].value === '1'){

			state[i].checked = true;
		}
	}

	// 发送ajax请求修改或添加数据
	document.getElementById('btn').onclick = function(){
		// 获取标签元素
		var rank = document.getElementsByClassName('rank');
		var menu = document.getElementsByClassName('menu');
		var link = document.getElementsByClassName('link');
		var classify = document.getElementsByClassName('classify');
		var id = document.getElementsByClassName('arrI');
		var state = document.getElementsByClassName('state');

		// 终止无参请求
		if(id.length < 1){
			
			return false;
		}

		// 初始化并累加赋值
		var arrR = [],
			arrM = [],
			arrI = [],
			arrL = [],
			arrC = [],
			arrS = [];
		for(var i = 0; i < rank.length; i++){

			arrR.push(rank[i].value);
			arrM.push(menu[i].value);
			arrL.push(link[i].value);
			arrI.push(id[i].innerHTML);
			arrC.push(classify[i].value);

			if(state[i].checked){
				arrS.push('1');		
			}else{
				arrS.push('0');
			}
		}

		// post方法请求数据
		ajax.post('./pose/menu_addAction.php', {'rank':arrR, 'menu':arrM, 'link':arrL, 'id':arrI, 'state':arrS, 'classify':arrC}, function(res){

			if(res.code === '1' && res.msg === '1'){

				UI.hint({'text':'恭喜您，操作成功！','icon':'ok1','load':'1'});
			}else{

				UI.hint({'text':'很遗憾，操作失败！'});
			}
		}, 'json');
	}
</script>